package com.atguigu.service.impl;

import com.atguigu.entities.User;
import com.atguigu.mapper.UserMapper;
import com.atguigu.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lbstart
 * @create 2021-06-27 9:33
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public int add(User user) {
        int i = userMapper.insertSelective(user);
        return i;
    }

    @Override
    public int del(Integer id) {
//        删除id比10大，并且比20小的数据
        Example example = new Example(User.class);

        Example.Criteria criteria = example.createCriteria();
        criteria.andGreaterThan("id",10);
        criteria.andLessThanOrEqualTo("id",20);

        return userMapper.deleteByExample(example);

    }

    @Override
    public int update(User user) {
        return 0;
    }

    @Override
    public User getById(Integer id) {
        User user = new User();
        user.setId(id);
        return  userMapper.selectOne(user);
    }

    @Override
    public List<User> getByCondition(User user) {
        return null;
    }

    @Override
    public List<User> getSplitPage(User user) {
        return null;
    }

    @Override
    public List<User> getSplitPageExample(User user) {
        return null;
    }
}
